﻿package bipede.animation
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class AnimationTimer extends Timer
	{
		public var MSPF:int = 40;// millisecond per frames
		public var type:String;
		public var cfg:Object;
		public var avancement:Number;// difference avec currentCount ?
		public var sens:Boolean=true;
		
		public function AnimationTimer( delay:Number=40, repeatCount:int=0 )
		{
			MSPF = delay;
			super( delay, repeatCount );
			
			addEventListener( TimerEvent.TIMER, _tick );			
			addEventListener( TimerEvent.TIMER_COMPLETE, _fin );			
		}
		public function configure( config:Object ):void
		{
			if ( cfg == null ) cfg = new Object();
			for ( var param:String in config ) cfg[ param ] = config[ param ];
		}
		public function _tick(e:TimerEvent):void
		{
		}
		public function _fin(e:TimerEvent):void
		{
		}
		override public function start():void
		{
			sens = true;
			avancement = 0;
			reset();
			restart();
		}	
		public function restart():void
		{
			super.start();	
		}			
		public function reverse():void
		{
			//sens = false;
			sens = !sens;
			restart();
		}		
	}
}